/**
 * Framework for batch testing user profile models
 * Final project by Sergey Nepomnyachiy and Julia Polchin
 * Supervisor: Tsvi Kuflik
 *
 */
package core.generators;

import static org.junit.Assert.assertTrue;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import org.junit.Before;
import org.junit.Test;

/**
 * Class encapsulating all the unit testing for generators
 * 
 * @author Sergey&Julia
 * 
 */
public class TestAllGens {

	/**
	 * Default constructor for test class
	 */
	public TestAllGens() {
		System.out.println("Test generators");
	}

	private DoubleSetGenerator dsg;
	private RandomDoubleSetGenerator rdsg;
	private StringSetGenerator ssg;
	private RandomStringSetGenerator rssg;
	private IntSetGenerator isg;
	private RandomIntSetGenerator risg;

	private IntRangeGenerator irg;
	private RandomIntRangeGenerator rirg;

	private StepIntGenerator sig;
	private StepDoubleGenerator sdg;

	/**
	 * Sets up the environment for testing - creates sets to test and assert
	 * upon
	 */
	@SuppressWarnings("boxing")
	@Before
	public void setUp() {
		final String doubleSet = "1.34,-1.2,3.14156,10";
		final String intSet = "1,2,-1,42";
		final String del = ",";
		this.dsg = new DoubleSetGenerator(doubleSet, del);
		this.rdsg = new RandomDoubleSetGenerator(doubleSet, del,0);
		this.ssg = new StringSetGenerator(doubleSet, del);
		this.rssg = new RandomStringSetGenerator(doubleSet, del,0);
		this.isg = new IntSetGenerator(intSet, del);
		this.risg = new RandomIntSetGenerator(intSet, del,0);

		this.irg = new IntRangeGenerator(-2, 5);
		this.rirg = new RandomIntRangeGenerator(-2, 5, 15, 12345);

		this.sig = new StepIntGenerator(3, 4);
		this.sig.generate(3);
		this.sdg = new StepDoubleGenerator(3.0, -0.5);
		this.sdg.generate(3);

	}

	/**
	 * Tests constructors of generators
	 */
	@Test
	public void constructor() {
		assertTrue(this.dsg != null);
		assertTrue(this.rdsg != null);
		assertTrue(this.ssg != null);
		assertTrue(this.rssg != null);
		assertTrue(this.isg != null);
		assertTrue(this.risg != null);

		assertTrue(this.irg != null);
		assertTrue(this.rirg != null);

		assertTrue(this.sig != null);
		assertTrue(this.sdg != null);
	}

	/**
	 * Unit test - validating the content of the generated data
	 */
	@SuppressWarnings("boxing")
	@Test
	public void content() {
		Set<Double> s = new TreeSet<Double>();
		s.add(1.34);
		s.add(-1.2);
		s.add(3.14156);
		s.add(Double.valueOf("10"));

		Set<Integer> si = new TreeSet<Integer>();
		si.add(1);
		si.add(2);
		si.add(-1);
		si.add(42);

		Set<Integer> stepTestI = new TreeSet<Integer>();
		stepTestI.add(3);
		stepTestI.add(7);
		stepTestI.add(11);

		Set<Double> stepTestD = new TreeSet<Double>();
		stepTestD.add(3.0);
		stepTestD.add(2.5);
		stepTestD.add(2.0);

		assertTrue(this.dsg.getScalar().equals(-1.2));
		assertTrue(this.ssg.getScalar().equals("-1.2"));
		assertTrue(this.isg.getScalar().equals(-1));

		Iterator<Double> it1 = this.dsg.getVector().iterator();
		for (Double d : s) {
			assertTrue(d.equals(it1.next()));
			assertTrue(this.rdsg.getVector().contains(d));
			if (!d.equals(10.0)) {
				assertTrue(this.rssg.getVector().contains(d.toString()));
				assertTrue(this.ssg.getVector().contains(d.toString()));
			}
		}

		Iterator<Integer> it2 = this.isg.getVector().iterator();
		for (Integer i : si) {
			assertTrue(i.equals(it2.next()));
			assertTrue(this.risg.getVector().contains(i));
		}

		for (Integer i : stepTestI) {
			assertTrue(this.sig.getVector().contains(i));
		}

		for (Double i : stepTestD) {
			assertTrue(this.sdg.getVector().contains(i));
		}
	}
}
